<h2>Search Catalogue</h2>
<hr/>
<p>To search a volume select the drop down field type and enter a valid search term.<br />
 To view a particular volume, select the view option.
 To modify a particular volume, select the modify option.
To delete a volume, select delete.
</p><br />
<center>

<?php echo form_open('admin/catalogue_management/searchCatalogue/'); ?>
<table>
<tr>
	<th align="right">Search by:</th>
	<td><?php echo form_dropdown('search_dropdown', array('title'=>'Title', 'subject'=>'Subject', 'author'=>'Author', 'access_id'=>'Accession Number', 'call_number'=>'Call Number')); ?></td>
	<?php echo form_hidden('table', 'tbl_volume'); ?>
	<?php echo form_hidden('search_by', 'title'); ?>
	<td><?php echo form_input('term', ''); ?></td>
	<td><?php echo form_submit('search', 'Submit'); ?></td>
</tr>
</table>
<?php echo form_close(); ?>

<p><?php echo $result_count ?> results returned.</p>

<table>
<tr>
<?php
foreach ($fields as $key=>$value)
	echo '<th>' . $value . '</th>';
?>
<th class="tablehead">Actions</th>
</tr>

<?php
foreach ($results->result() as $result)
{
	if ($action['Type'] == 'Volume' && $result->on_loan)
		echo '<tr bgcolor="#BBBBBB">';
	
	else
		echo '<tr>';
	
	foreach ($fields as $key=>$value)
		echo '<td>' . $result->$key . '</td>';
	
	// Actions
	echo '<td>';
	echo anchor('admin/catalogue_management/view' . $action['Type'] . '/' . $result->$action['UniqueID'], 'View' ) . '/';
	echo anchor('admin/catalogue_management/modify' . $action['Type'] . '/' . $result->$action['UniqueID'], 'Modify' ) . '/';
	echo anchor('admin/catalogue_management/delete' . $action['Type'] . '/' . $result->$action['UniqueID'], 'Delete', array('onclick'=>"return confirm('Are you sure you wish to remove this entry?');") );
	echo '</br></td>';
	echo '</tr>';
}
?>
</table>

<?php echo $this->pagination->create_links(); ?>

</center>

<script type="text/javascript">
$(document).ready(function() {
	addAutocomplete('[name="term"]', '<?php echo site_url('admin/jquery/autocomplete/tbl_volume/title'); ?>');
	
	$("[name=search_dropdown]").change( function(){
		if ($("[name=search_dropdown]").val() == 'access_id')
		{
			$("[name=table]").val('tbl_volume');
			$("[name=search_by]").val('access_id');
			addAutocomplete('[name="term"]', '<?php echo site_url('admin/jquery/autocomplete/tbl_volume/access_id'); ?>');
		}
		
		if ($("[name=search_dropdown]").val() == 'call_number')
		{
			$("[name=table]").val('tbl_volume');
			$("[name=search_by]").val('call_number');
			addAutocomplete('[name="term"]', '<?php echo site_url('admin/jquery/autocomplete/tbl_volume/call_number'); ?>');
		}
		
		if ($("[name=search_dropdown]").val() == 'title')
		{
			$("[name=table]").val('tbl_volume');
			$("[name=search_by]").val('title');
			addAutocomplete('[name="term"]', '<?php echo site_url('admin/jquery/autocomplete/tbl_volume/title'); ?>');
		}
		
		if ($("[name=search_dropdown]").val() == 'subject')
		{
			$("[name=table]").val('tbl_subject');
			$("[name=search_by]").val('subject_name');
			addAutocomplete('[name="term"]', '<?php echo site_url('admin/jquery/autocomplete/tbl_subject/subject_name'); ?>');
		}
		
		if ($("[name=search_dropdown]").val() == 'author')
		{
			$("[name=table]").val('tbl_author');
			$("[name=search_by]").val('author_name');
			addAutocomplete('[name="term"]', '<?php echo site_url('admin/jquery/autocomplete/tbl_author/author_name'); ?>');
		}
	});
});
</script>